package com.project.dao.impl;

import java.sql.*;
/**
 * @Title: BaseDao
 * @Package: com.project.bean
 * @Description:
 * @Author: Liang-Xie
 * @Date: 2022/6/30 - 11:24
 */
@SuppressWarnings("all")
public class BaseDao {

    protected Connection con;
    protected PreparedStatement ps;
    protected ResultSet rs;

    public void setConnection(){
        try {
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://localhost:1234/mydb?characterEncoding=utf-8","root","lovo");
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }
    }

    public void close(){
        if (rs != null){
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (ps != null){
            try {
                ps.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (con != null){
            try {
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 更新数据库的数据
     * @param sql 执行的sql语句
     * @param valueArray 值列表
     */
    public static void updateData(String sql,Object...valueArray){

    }

//    public static void main(String[] args) {
//        updateData("",new Object[]{30,"333","333"});
//        updateData("",90,"333","333");
//    }
}
